<template>
  <div class="home-demo">
      <input type="text" v-model="keyWord">
      {{keyWord}}
  </div>
</template>

<script>
import { customRef } from 'vue'
export default {
  name: 'HomeDemo',
  setup () {
    function linwtRef (value, delay) {
      let timer
      return customRef((track, triger) => {
        return {
          get () {
            track()
            return value
          },
          set (newVal) {
            setTimeout(() => {
              clearTimeout(timer)
              value = newVal
              triger()
            }, delay)
          }
        }
      })
    }
    const keyWord = linwtRef('hello', 500)
    return {
      keyWord
    }
  }
}
</script>
